﻿using System.Data;
using System.Data.SqlClient;

namespace MyWeb.Data
{
    public class ContactController : SqlDataProvider
    {
        #region [Contact_GetByAll]

        public DataTable Contact_GetByAll()
        {
            return GetDataTable("sp_Contact_GetByAll");
        }

        #endregion

        #region [Contact_GetById]

        public DataTable Contact_GetById(int id)
        {
            var p1 = new SqlParameter("@id", id);
            return GetDataTable("sp_Contact_GetById", p1);
        }

        #endregion

        #region [Contact_Insert]

        public void Contact_Insert(ContactInfo contact)
        {
            var p1 = new SqlParameter("@Name", contact.Name);
            var p2 = new SqlParameter("@Company", contact.Company);
            var p3 = new SqlParameter("@Address", contact.Address);
            var p4 = new SqlParameter("@Tel", contact.Tel);
            var p5 = new SqlParameter("@Mail", contact.Mail);
            var p6 = new SqlParameter("@Detail", contact.Detail);
            var p7 = new SqlParameter("@Date", contact.Date);
            ExecuteStoreProcedure("sp_Contact_Insert", p1, p2, p3, p4, p5, p6, p7);
        }

        #endregion

        #region [Contact_Update]

        public void Contact_Update(ContactInfo contact)
        {
            var p0 = new SqlParameter("@Id", contact.Id);
            var p1 = new SqlParameter("@Name", contact.Name);
            var p2 = new SqlParameter("@Company", contact.Company);
            var p3 = new SqlParameter("@Address", contact.Address);
            var p4 = new SqlParameter("@Tel", contact.Tel);
            var p5 = new SqlParameter("@Mail", contact.Mail);
            var p6 = new SqlParameter("@Detail", contact.Detail);
            var p7 = new SqlParameter("@Date", contact.Date);
            ExecuteStoreProcedure("sp_Contact_Update", p0, p1, p2, p3, p4, p5, p6, p7);
        }

        #endregion

        #region [Contact_Delete]

        public void Contact_Delete(int id)
        {
            var p0 = new SqlParameter("@Id", id);
            ExecuteStoreProcedure("sp_Contact_Delete", p0);
        }

        #endregion
    }
}